package com.zhou.util;

import java.util.ArrayList;

import com.zhou.yuefan.R;
import com.zhou.yuefan.dao.GetNameInterface;
import com.zhou.yuefan.model.Food;
import com.zhou.yuefan.model.Shop;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DateAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<Shop> lstName;
	private TextView txtAge;

	public DateAdapter(Context mContext, ArrayList<Shop> list) {
		this.context = mContext;
		lstName = list;
	}

	@Override
	public int getCount() {
		return lstName.size();
	}

	@Override
	public Object getItem(int position) {
		return lstName.get(position);
	}

	@Override
	public long getItemId(int position) {
		try {
			return lstName.get(position).getId();
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return 1 ;
	}

	public void exchange(int startPosition, int endPosition) {
		lstName.set(endPosition,
				lstName.set(startPosition, (Shop) getItem(endPosition)));

		/*
		 * Object endObject = getItem(endPosition); Object startObject =
		 * getItem(startPosition); lstDate.add(startPosition, (String)
		 * endObject); lstDate.remove(startPosition + 1);
		 * lstDate.add(endPosition, (String) startObject);
		 * lstDate.remove(endPosition + 1);
		 */
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = LayoutInflater.from(context).inflate(R.layout.shops_item,
				null);
		
		txtAge = (TextView) convertView.findViewById(R.id.txt_userAge);
		if (lstName.get(position) == null) {
			txtAge.setText("+");
			txtAge.setBackgroundResource(R.color.red_shop_back);
		} 
		else if (lstName.get(position).equals("none")) {
			txtAge.setText("");
			txtAge.setBackgroundDrawable(null);
			
			
		} 
		else
			txtAge.setText(lstName.get(position).getName());
		return convertView;
	}
	
	

}
